package com.hyt.it.ogt.ks.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.common.apiInfor.DataType;
import com.hyt.common.apiInfor.ParamType;
import com.hyt.it.ogt.ks.enums.BizStatusCode;
import com.hyt.it.ogt.ks.model.entity.mongodb.CandidateAnswerLog;
import com.hyt.it.ogt.ks.service.CandidateAnswerLogService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;
import lombok.extern.slf4j.Slf4j;

/**
 * @author wuyingge
 * @version 1.0.0
 * @ClassName CandidateAnswerLogController.java
 * @Description 考生答题轨迹
 * @createTime 2022年04月05日 14:51:00
 */
@RestController
@RequestMapping("/ks/candidateLog")
@Api(tags = "15.考生答题轨迹", value = "考生答题轨迹")
@ApiSort(15)
@Slf4j
public class CandidateAnswerLogController {
    @Resource
    private CandidateAnswerLogService candidateAnswerLogService;


    @GetMapping("/query")
    @ApiOperation(value = "15.1.1 考生答题轨迹查询", notes = "状态码：20000 成功，41150102 异常")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "candidateId", value = "考生id", dataType = DataType.STRING,
                    paramType = ParamType.QUERY, required = true)
    })
    @ApiOperationSort(1)
    public Object query(@RequestParam String candidateId) {
        log.info("查询考生mongodb答题日志，收到参数为:【{}】",candidateId);
        try {
            List<CandidateAnswerLog> data = candidateAnswerLogService.getCandidateLogsByCandidateId(candidateId);
            return com.hyt.common.apiInfor.ApiResponse.builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(data)
                    .build();
        } catch (Exception ex) {
            log.error("查询考生mongodb答题日志，收到参数为:【{}】,", candidateId,ex);
            return ApiResponse.builder()
                    .code(BizStatusCode.CANDIDATE_ANSWER_LOG_ERROR.getCode())
                    .build();
        }
    }
}
